<?php


abstract class BaseEvento extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $uid;


	
	protected $m;


	
	protected $d;


	
	protected $y;


	
	protected $start_time;


	
	protected $end_time;


	
	protected $title;


	
	protected $text;

	
	protected $collHorarios;

	
	protected $lastHorarioCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getUid()
	{

		return $this->uid;
	}

	
	public function getM()
	{

		return $this->m;
	}

	
	public function getD()
	{

		return $this->d;
	}

	
	public function getY()
	{

		return $this->y;
	}

	
	public function getStartTime($format = 'H:i:s')
	{

		if ($this->start_time === null || $this->start_time === '') {
			return null;
		} elseif (!is_int($this->start_time)) {
						$ts = strtotime($this->start_time);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [start_time] as date/time value: " . var_export($this->start_time, true));
			}
		} else {
			$ts = $this->start_time;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getEndTime($format = 'H:i:s')
	{

		if ($this->end_time === null || $this->end_time === '') {
			return null;
		} elseif (!is_int($this->end_time)) {
						$ts = strtotime($this->end_time);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [end_time] as date/time value: " . var_export($this->end_time, true));
			}
		} else {
			$ts = $this->end_time;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getTitle()
	{

		return $this->title;
	}

	
	public function getText()
	{

		return $this->text;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = EventoPeer::ID;
		}

	} 
	
	public function setUid($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->uid !== $v) {
			$this->uid = $v;
			$this->modifiedColumns[] = EventoPeer::UID;
		}

	} 
	
	public function setM($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->m !== $v) {
			$this->m = $v;
			$this->modifiedColumns[] = EventoPeer::M;
		}

	} 
	
	public function setD($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->d !== $v) {
			$this->d = $v;
			$this->modifiedColumns[] = EventoPeer::D;
		}

	} 
	
	public function setY($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->y !== $v) {
			$this->y = $v;
			$this->modifiedColumns[] = EventoPeer::Y;
		}

	} 
	
	public function setStartTime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [start_time] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->start_time !== $ts) {
			$this->start_time = $ts;
			$this->modifiedColumns[] = EventoPeer::START_TIME;
		}

	} 
	
	public function setEndTime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [end_time] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->end_time !== $ts) {
			$this->end_time = $ts;
			$this->modifiedColumns[] = EventoPeer::END_TIME;
		}

	} 
	
	public function setTitle($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->title !== $v) {
			$this->title = $v;
			$this->modifiedColumns[] = EventoPeer::TITLE;
		}

	} 
	
	public function setText($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->text !== $v) {
			$this->text = $v;
			$this->modifiedColumns[] = EventoPeer::TEXT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->uid = $rs->getInt($startcol + 1);

			$this->m = $rs->getInt($startcol + 2);

			$this->d = $rs->getInt($startcol + 3);

			$this->y = $rs->getInt($startcol + 4);

			$this->start_time = $rs->getTime($startcol + 5, null);

			$this->end_time = $rs->getTime($startcol + 6, null);

			$this->title = $rs->getString($startcol + 7);

			$this->text = $rs->getString($startcol + 8);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Evento object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(EventoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			EventoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(EventoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = EventoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += EventoPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collHorarios !== null) {
				foreach($this->collHorarios as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = EventoPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collHorarios !== null) {
					foreach($this->collHorarios as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = EventoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUid();
				break;
			case 2:
				return $this->getM();
				break;
			case 3:
				return $this->getD();
				break;
			case 4:
				return $this->getY();
				break;
			case 5:
				return $this->getStartTime();
				break;
			case 6:
				return $this->getEndTime();
				break;
			case 7:
				return $this->getTitle();
				break;
			case 8:
				return $this->getText();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = EventoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUid(),
			$keys[2] => $this->getM(),
			$keys[3] => $this->getD(),
			$keys[4] => $this->getY(),
			$keys[5] => $this->getStartTime(),
			$keys[6] => $this->getEndTime(),
			$keys[7] => $this->getTitle(),
			$keys[8] => $this->getText(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = EventoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUid($value);
				break;
			case 2:
				$this->setM($value);
				break;
			case 3:
				$this->setD($value);
				break;
			case 4:
				$this->setY($value);
				break;
			case 5:
				$this->setStartTime($value);
				break;
			case 6:
				$this->setEndTime($value);
				break;
			case 7:
				$this->setTitle($value);
				break;
			case 8:
				$this->setText($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = EventoPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUid($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setM($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setD($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setY($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setStartTime($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setEndTime($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setTitle($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setText($arr[$keys[8]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(EventoPeer::DATABASE_NAME);

		if ($this->isColumnModified(EventoPeer::ID)) $criteria->add(EventoPeer::ID, $this->id);
		if ($this->isColumnModified(EventoPeer::UID)) $criteria->add(EventoPeer::UID, $this->uid);
		if ($this->isColumnModified(EventoPeer::M)) $criteria->add(EventoPeer::M, $this->m);
		if ($this->isColumnModified(EventoPeer::D)) $criteria->add(EventoPeer::D, $this->d);
		if ($this->isColumnModified(EventoPeer::Y)) $criteria->add(EventoPeer::Y, $this->y);
		if ($this->isColumnModified(EventoPeer::START_TIME)) $criteria->add(EventoPeer::START_TIME, $this->start_time);
		if ($this->isColumnModified(EventoPeer::END_TIME)) $criteria->add(EventoPeer::END_TIME, $this->end_time);
		if ($this->isColumnModified(EventoPeer::TITLE)) $criteria->add(EventoPeer::TITLE, $this->title);
		if ($this->isColumnModified(EventoPeer::TEXT)) $criteria->add(EventoPeer::TEXT, $this->text);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(EventoPeer::DATABASE_NAME);

		$criteria->add(EventoPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUid($this->uid);

		$copyObj->setM($this->m);

		$copyObj->setD($this->d);

		$copyObj->setY($this->y);

		$copyObj->setStartTime($this->start_time);

		$copyObj->setEndTime($this->end_time);

		$copyObj->setTitle($this->title);

		$copyObj->setText($this->text);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getHorarios() as $relObj) {
				$copyObj->addHorario($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new EventoPeer();
		}
		return self::$peer;
	}

	
	public function initHorarios()
	{
		if ($this->collHorarios === null) {
			$this->collHorarios = array();
		}
	}

	
	public function getHorarios($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collHorarios === null) {
			if ($this->isNew()) {
			   $this->collHorarios = array();
			} else {

				$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

				HorarioPeer::addSelectColumns($criteria);
				$this->collHorarios = HorarioPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

				HorarioPeer::addSelectColumns($criteria);
				if (!isset($this->lastHorarioCriteria) || !$this->lastHorarioCriteria->equals($criteria)) {
					$this->collHorarios = HorarioPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastHorarioCriteria = $criteria;
		return $this->collHorarios;
	}

	
	public function countHorarios($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

		return HorarioPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addHorario(Horario $l)
	{
		$this->collHorarios[] = $l;
		$l->setEvento($this);
	}


	
	public function getHorariosJoinAteneausuario($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collHorarios === null) {
			if ($this->isNew()) {
				$this->collHorarios = array();
			} else {

				$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

				$this->collHorarios = HorarioPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		} else {
									
			$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

			if (!isset($this->lastHorarioCriteria) || !$this->lastHorarioCriteria->equals($criteria)) {
				$this->collHorarios = HorarioPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		}
		$this->lastHorarioCriteria = $criteria;

		return $this->collHorarios;
	}


	
	public function getHorariosJoinTurno($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collHorarios === null) {
			if ($this->isNew()) {
				$this->collHorarios = array();
			} else {

				$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

				$this->collHorarios = HorarioPeer::doSelectJoinTurno($criteria, $con);
			}
		} else {
									
			$criteria->add(HorarioPeer::EVENTO_ID, $this->getId());

			if (!isset($this->lastHorarioCriteria) || !$this->lastHorarioCriteria->equals($criteria)) {
				$this->collHorarios = HorarioPeer::doSelectJoinTurno($criteria, $con);
			}
		}
		$this->lastHorarioCriteria = $criteria;

		return $this->collHorarios;
	}

} 